package com.briup.smartcity.web.controller;

import com.briup.smartcity.bean.Comment;
import com.briup.smartcity.service.ICommentService;
import com.briup.smartcity.utils.Result;
import com.briup.smartcity.utils.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "评论管理模块")
@RestController
@RequestMapping("/auth/comment")
public class CommentController {

    @Autowired
    private ICommentService service;

    @ApiOperation("根据id删除评论信息")
    @DeleteMapping("/deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam (name = "id",value = "评论编号",dataType = "int")
    })
    public Result deleteCommentById(Integer id) {
        service.deleteById(id);
        return ResultUtil.success();
    }

    @ApiOperation("分页查询评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam (name = "pageNum",value = "当前页码",dataType = "int"),
            @ApiImplicitParam (name = "pageSize",value = "每页大小",dataType = "int"),
            @ApiImplicitParam (name = "keywords",value = "关键词",dataType = "string")
    })
    @GetMapping("/pageQuery")
    public Result findAllCommentByPage(int pageNum,int pageSize,String keywords){
        //执行查询分页
        PageInfo<Comment> pageInfo = service.pageQuery(pageNum,pageSize ,keywords);
        return ResultUtil.success(pageInfo);
    }
    @ApiOperation(value = "审核评论状态")
    @ApiImplicitParams({
            @ApiImplicitParam (name = "id",value = "评论编号"),
            @ApiImplicitParam (name = "id",value = "审核状态：0 待审核，1 不通过，2 通过")
    })
    @PutMapping("/check")
    public Result checkComment(int id,int status){
        service.checkComment(id,status);
        return ResultUtil.success();
    }
    @ApiOperation("批量删除评论")
    @DeleteMapping("/batchDelete")
    public Result batchDeleteComment(int[] ids){
        service.batchDelete(ids);
        return ResultUtil.success();
    }
}
